package top.yueyazhui.storage.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.yueyazhui.storage.mapper.StorageMapper;
import top.yueyazhui.storage.service.StorageService;

@Service
public class StorageServiceImpl implements StorageService {

    @Autowired
    StorageMapper storageMapper;

    @Override
    public boolean deductStorage(String commodityCode, Integer count) {
        Integer result = storageMapper.getCountByCommodityCode(commodityCode);
        if (result < count) {
            throw new RuntimeException("库存不足");
        }
        storageMapper.deductStorage(commodityCode, count);
        return true;
    }
}
